<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Document</title>
		<style>
			body {
				margin: 0;
			}

			#div1 {
				width: 300px;
				height: 300px;
				background: red;
				position: absolute;
				left: 0;
				top: 0;
			}
		</style>
	</head>

	<body>
		<div id="div1"></div>
	</body>

</html>
<script>
	var div1 = document.getElementById('div1')
	div1.onmousedown = function(event) {
		var chaX = event.clientX - div1.offsetLeft
		var chaY = event.clientY - div1.offsetTop

		document.onmousemove = function(event) {
			div1.style.left = event.clientX - chaX + 'px'
			div1.style.top = event.clientY - chaY + 'px'
			
			console.log('div1.style.left:', div1.style.left)
			console.log('div1.style.top:', div1.style.top)
		}

		document.onmouseup = function() {
			document.onmousemove = null
		}
	}
</script>